#include <my_head.h>

int main(int argc, const char *argv[]){
    int fd1 = open("fifo1", O_RDONLY);
    int fd2 = open("fifo2", O_RDONLY);
    int fd3 = open("fifo3", O_RDONLY);

    // 设置非阻塞
    int flag = 0;
    flag = fcntl(fd1, F_GETFL);
    flag |= O_NONBLOCK;
    fcntl(fd1, F_SETFL, flag);
    
    flag = fcntl(fd2, F_GETFL);
    flag |= O_NONBLOCK;
    fcntl(fd2, F_SETFL, flag);
    
    flag = fcntl(fd3, F_GETFL);
    flag |= O_NONBLOCK;
    fcntl(fd3, F_SETFL, flag);


    char buff[128] = {0};
    while(1){
        memset(buff, 0, sizeof(buff));
        read(fd1, buff, sizeof(buff));
        printf("fd1=[%s]\n", buff);

        memset(buff, 0, sizeof(buff));
        read(fd2, buff, sizeof(buff));
        printf("fd2=[%s]\n", buff);

        memset(buff, 0, sizeof(buff));
        read(fd3, buff, sizeof(buff));
        printf("fd3=[%s]\n", buff);

        // 此处的sleep就是为了防止刷屏方便看现象的
        // 如果没有这个sleep 会发现 没有写端发数据时 读端处于运行态
        // sleep(1);
    }

    close(fd1);
    close(fd2);
    close(fd3);

    return 0;
}